#ifndef _MATHEMATICS_ALGEBRA_LINEAR_EQUATION_
#define _MATHEMATICS_ALGEBRA_LINEAR_EQUATION_

#include "equation.h"

#include <iostream>
#include <math.h>

namespace science
{
	namespace mathematics
	{
		namespace algebra
		{
			class linear_equation : public equation
			{
			public:
				linear_equation()
				{

				}

				linear_equation(double a, double b)
				{
					if (math_helper::double_check(a, 0) == 0)
						throw new std::invalid_argument("The x coefficient cannot be zero");
					_lhs = expression_fraction(expression::constant(a) * expression::unit() + expression::constant(b));
					_rhs = expression_fraction(expression::constant(0));
				}

				linear_equation(std::string equation_str)
					: equation(equation_str)
				{
					
				}

				virtual ~linear_equation()
				{

				}

			public:
				double get_a() { return _lhs.get_numerator().get_term(0).get_coeffiecient(); }
				double get_b() { return _lhs.get_numerator().get_term(1).get_coeffiecient(); }

			public:

				double linear_solve()
				{
					double sol = -get_b() / get_a();
					return sol;
				}

				virtual set<set<double>> solve()
				{					
					set<set<double>> solution;
					solution.add_element(set<double>({ linear_solve() }));
					return solution;
				}		

			public:
				friend std::istream &operator>>(std::istream  &input, linear_equation &eq)
				{
					double a, b, c;
					char equals, sign, var;
					input >> a >> var >> sign >> b >> equals >> c;
					if (sign == '-')
						b = -b;
					b = b - c;
					
					eq = linear_equation(a, b);
					return input;
				}
			};
		}
	}
}

#endif